Use g_date_strftime() for UTF-8 correctness; use Julian dates to simplify
authorFederico Mena Quintero <federico@ximian.com>
Fri, 19 Dec 2003 17:38:54 +0000 (17:38 +0000)
committerFederico Mena Quintero <federico@src.gnome.org>
Fri, 19 Dec 2003 17:38:54 +0000 (17:38 +0000)
2003-12-19  Federico Mena Quintero  <federico@ximian.com>

* gtk/gtkfilechooserdefault.c (list_mtime_data_func): Use
g_date_strftime() for UTF-8 correctness; use Julian dates to
simplify the function.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkfilechooserdefault.c

index 46b2ce9bcdedcc4a33f1c9ed9e071f021b903f1e..4273c223ff5908b48f45626466da3bbbd070490f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2003-12-19  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilechooserdefault.c (list_mtime_data_func): Use
+       g_date_strftime() for UTF-8 correctness; use Julian dates to
+       simplify the function.
+
 Fri Dec 19 01:47:34 2003  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkscrolledwindow.c (gtk_scrolled_window_size_request): 
index 46b2ce9bcdedcc4a33f1c9ed9e071f021b903f1e..4273c223ff5908b48f45626466da3bbbd070490f 100644 (file)
@@ -1,3 +1,9 @@
+2003-12-19  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilechooserdefault.c (list_mtime_data_func): Use
+       g_date_strftime() for UTF-8 correctness; use Julian dates to
+       simplify the function.
+
 Fri Dec 19 01:47:34 2003  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkscrolledwindow.c (gtk_scrolled_window_size_request): 
index 46b2ce9bcdedcc4a33f1c9ed9e071f021b903f1e..4273c223ff5908b48f45626466da3bbbd070490f 100644 (file)
@@ -1,3 +1,9 @@
+2003-12-19  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilechooserdefault.c (list_mtime_data_func): Use
+       g_date_strftime() for UTF-8 correctness; use Julian dates to
+       simplify the function.
+
 Fri Dec 19 01:47:34 2003  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkscrolledwindow.c (gtk_scrolled_window_size_request): 
index 46b2ce9bcdedcc4a33f1c9ed9e071f021b903f1e..4273c223ff5908b48f45626466da3bbbd070490f 100644 (file)
@@ -1,3 +1,9 @@
+2003-12-19  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilechooserdefault.c (list_mtime_data_func): Use
+       g_date_strftime() for UTF-8 correctness; use Julian dates to
+       simplify the function.
+
 Fri Dec 19 01:47:34 2003  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkscrolledwindow.c (gtk_scrolled_window_size_request): 
index 46b2ce9bcdedcc4a33f1c9ed9e071f021b903f1e..4273c223ff5908b48f45626466da3bbbd070490f 100644 (file)
@@ -1,3 +1,9 @@
+2003-12-19  Federico Mena Quintero  <federico@ximian.com>
+
+       * gtk/gtkfilechooserdefault.c (list_mtime_data_func): Use
+       g_date_strftime() for UTF-8 correctness; use Julian dates to
+       simplify the function.
+
 Fri Dec 19 01:47:34 2003  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkscrolledwindow.c (gtk_scrolled_window_size_request): 
index 0b037895cc3d6db9614f6535e4933ab7e44661b5..07979875b072471f2627c5cfab811f04bf583571 100644 (file)
@@ -2972,8 +2972,9 @@ list_mtime_data_func (GtkTreeViewColumn *tree_column,
 {
   GtkFileChooserDefault *impl;
   const GtkFileInfo *info;
-  time_t mtime, now;
-  struct tm tm, now_tm;
+  GtkFileTime time_mtime, time_now;
+  GDate mtime, now;
+  int days_diff;
   char buf[256];
 
   impl = data;
@@ -2982,52 +2983,29 @@ list_mtime_data_func (GtkTreeViewColumn *tree_column,
   if (!info)
     return;
 
-  mtime = (time_t) gtk_file_info_get_modification_time (info);
-  tm = *localtime (&mtime);
+  time_mtime = gtk_file_info_get_modification_time (info);
+  g_date_set_time (&mtime, (GTime) time_mtime);
 
-  now = time (NULL);
-  now_tm = *localtime (&now);
+  time_now = (GTime ) time (NULL);
+  g_date_set_time (&now, (GTime) time_now);
 
-  /* Today */
-  if (tm.tm_mday == now_tm.tm_mday
-      && tm.tm_mon == now_tm.tm_mon
-      && tm.tm_year == now_tm.tm_year)
+  days_diff = g_date_get_julian (&now) - g_date_get_julian (&mtime);
+
+  if (days_diff == 0)
     strcpy (buf, _("Today"));
+  else if (days_diff == 1)
+    strcpy (buf, _("Yesterday"));
   else
     {
-      int i;
-
-      /* Days from last week */
-
-      for (i = 1; i < 7; i++)
-       {
-         time_t then;
-         struct tm then_tm;
-
-         then = now - i * 60 * 60 * 24;
-         then_tm = *localtime (&then);
-
-         if (tm.tm_mday == then_tm.tm_mday
-             && tm.tm_mon == then_tm.tm_mon
-             && tm.tm_year == then_tm.tm_year)
-           {
-             if (i == 1)
-               strcpy (buf, _("Yesterday"));
-             else
-               if (strftime (buf, sizeof (buf), "%A", &tm) == 0)
-                 strcpy (buf, _("Unknown"));
-
-             break;
-           }
-       }
+      char *format;
 
-      /* Any other date */
+      if (days_diff > 1 && days_diff < 7)
+       format = "%A"; /* Days from last week */
+      else
+       format = _("%d/%b/%Y"); /* Any other date */
 
-      if (i == 7)
-       {
-         if (strftime (buf, sizeof (buf), _("%d/%b/%Y"), &tm) == 0)
-           strcpy (buf, _("Unknown"));
-       }
+      if (g_date_strftime (buf, sizeof (buf), format, &mtime) == 0)
+       strcpy (buf, _("Unknown"));
     }
 
   set_cell_text_bold_if_folder (info, cell, buf);